<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>关联配置</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css"/>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <script src="/static/component/pear/module/ruinuo/sortable.js"></script>
    <script src="/static/component/pear/module/ruinuo/xm-select.js"></script>
</head>
<body>
<div class="view_body">
    <form class="layui-form" action="">
        <div class="ruinuo_box">
            <div class="main-container layui-row layui-col-space10 label_con">
                <fieldset class="layui-elem-field layui-field-title layui-col-xs12">
                    <legend class="tips_legend">设置说明</legend>
                </fieldset>
                <blockquote class="layui-elem-quote tips_legend layui-col-xs12">
                    1、回调字段：弹窗打开的表格已存在字段<br>
                    2、存储字段：表单中已存在字段<br>
                    3、回调字段与存储字段是对应关系，一定要对应好
                </blockquote>
                <div class="design-box layui-col-xs12 layui-col-md12 field_box">
                    <div class="layui-input-block  block_margin_left_0">
                        <textarea name="field" id="focus_1712541319_7" class="layui-input" style="display: none"
                                  lay-filter="json_filter"></textarea>
                        <div class="table_1712541319_7 f_table">
                            <table id="table_1712541319_7" lay-filter="filter_1712541319_7"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </form>

</div>

<script>


    let SettingData = {};
    let SeleteData = {};
    let current = 1;
    let raw = '';
    let InitData = {};
    let $ = layui.jquery;
    layui.use(['form', 'http', 'public', 'engine_form'], function () {
        FormBind();
    })

    function FormBind() {
        let save_field = [];
        let fields = parent.layui.design_form.GetFieldData();
        fields.forEach(item => {
            save_field.push({label: item.title + '_' + item.field, value: item.field});
        })

        let data = $(".design-right-con textarea[name='event_val']", window.parent.document).val() || '[]';
        $("#focus_1712541319_7").val(data);
        InitData['source'] = {
            open_type: {
                rows: [
                    {label: '存储', value: '1'},
                    {label: '显示', value: '2'},
                ]
            },
            save_field: {
                rows: save_field
            }
        };

        let tablefield = {
            "title": "字段",
            "field": "field",
            "tag": "jsontable",
            "type": "json",
            "required": 1,
            "verify": "json",
            "hide_label": 1,
            "elem_id": "1712541319_7",
            "cols": [
                {
                    "title": "回调字段",
                    "field": "show_field",
                    "update": "input",
                    "required": 1
                }, {
                    "title": "存储字段",
                    "field": "save_field",
                    "update": "select",
                    "required": 1,
                    "options": "save_field",
                }
            ],
        };
        layui.engine_form.BindJsonTable(tablefield);
    }

    function SendForm() {
        let json = $("textarea[name='field']").val() || '[]';
        let fields = eval(json);
        let msg = '';
        fields.forEach((item, index) => {
            let show_field = item.show_field || '';
            let save_field = item.save_field || '';
            if (show_field == '' || save_field == '') {
                msg = '必填项不能为空'
            }


        })
        if (msg) {
            layui.layer.msg(msg, {icon: 2});
            return false;
        }
        return JSON.stringify(fields);
    }
</script>
</body>
</html>

